<template>
  <div class="app-container">
    <SearchContent :queryParams="queryParams" @query="handleQuery" @reset="resetQuery">
      <el-col :span="6">
        <el-form-item label="业务来源:" prop="businessSource">
          <el-select v-model="queryParams.businessSource" clearable>
            <template v-for="dict in dict.type.business_source">
              <el-option :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
            </template>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="产品方案名称:" prop="schemeName">
          <!-- <el-input v-model="queryParams.schemeName" clearable placeholder="请输入产品方案名称"></el-input> -->
          <el-select v-model="queryParams.schemeName" placeholder="请选择产品方案名称" clearable filterable>
            <el-option v-for="item in schemeNameList" :key="item" :label="item" :value="item">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="产品方案编号:" prop="schemeNo">
          <!-- <el-input v-model="queryParams.schemeNo" clearable placeholder="请输入产品方案编号"></el-input> -->
          <el-select v-model="queryParams.schemeNo" placeholder="请选择产品方案编号" clearable filterable>
            <el-option v-for="item in schemeNoList" :key="item" :label="item" :value="item">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="编辑人员:" prop="editUserName">
          <!-- <el-input v-model="queryParams.editUserName" clearable placeholder="请输入编辑人员"></el-input> -->
          <el-select v-model="queryParams.editUserName" placeholder="请选择编辑人员" clearable filterable>
            <el-option v-for="item in editUserNameList" :key="item" :label="item" :value="item">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="版本号:" prop="version">
          <!-- <el-input v-model="queryParams.version" clearable placeholder="请输入版本号" @input="queryParams.version=queryParams.version.replace(/^0|[^0-9]/g, '')"></el-input> -->
          <el-select v-model="queryParams.version" placeholder="请选择版本号" clearable filterable>
            <el-option v-for="item in versionList" :key="item" :label="item" :value="item">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="产品方案类型:" prop="schemeType">
          <el-select v-model="queryParams.schemeType" clearable>
            <template v-for="dict in dict.type.product_scheme_type">
              <el-option :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
            </template>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="状态:" prop="shelveStatus">
          <el-select v-model="queryParams.shelveStatus" clearable>
            <template v-for="dict in dict.type.product_solution_status">
              <el-option :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
            </template>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="车型范围:" prop="vehicleRangeType">
          <el-select v-model="queryParams.vehicleRangeType" clearable>
            <template v-for="dict in dict.type.vehicle_range">
              <el-option :label="dict.label" :value="dict.value" :key="dict.value"></el-option>
            </template>
          </el-select>
        </el-form-item>
      </el-col>
    </SearchContent>

    <div class="card-wrap card-padding">
      <div class="table-title-wrap justify-end" v-hasPermi="['globalField:productScheme:add']">
        <el-button type="primary" size="mini" @click="handleAdd">新增</el-button>
      </div>

      <table-page :loading="loading" :dataList="dataList" border :total="total" :pageSizes="pageSizes" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @setSizeCurrent="getList">
        <!-- 操作插槽 -->
        <template slot="tableColAc">
          <el-table-column label="操作" width="240" align="center">
            <template slot-scope="scope">
              <div style="display: flex;flex-wrap: nowrap;justify-content: center;">
                <span v-if="scope.row.draftType == 0 ">
                  <el-button type="text" :class="{'text':scope.row.shelveStatus ==0}" v-hasPermi="['globalField:productScheme:detail']" v-if="scope.row.shelveStatus == 1 || scope.row.shelveStatus == 0" @click="goToDetail(scope.row)">详情</el-button>
                  <el-button type="text" :class="{'text':scope.row.shelveStatus ==0}" v-hasPermi="['globalField:productScheme:delist']" v-if="scope.row.shelveStatus == 1" @click="delist(scope.row)">下架</el-button>
                  <e-button size="mini" :class="{'text':scope.row.shelveStatus ==0}" v-hasPermi="['globalField:productScheme:edit']" v-if="scope.row.shelveStatus == 0" type="text" @click="handleUpdate(scope.row)">编辑</e-button>
                  <el-button type="text" :class="{'text':scope.row.shelveStatus ==0}" v-hasPermi="['globalField:productScheme:listing']" v-if="scope.row.shelveStatus == 0" @click="listing(scope.row)">上架</el-button>
                </span>
                <span v-if="scope.row.draftType == 1 ">
                  <el-button type="text" :class="{'text':scope.row.shelveStatus ==0}" v-hasPermi="['globalField:productScheme:detail']" v-if="scope.row.shelveStatus == 0" @click="goToDetail(scope.row)">详情</el-button>
                  <e-button size="mini" :class="{'text':scope.row.shelveStatus ==0}" v-hasPermi="['globalField:productScheme:edit']" v-if="scope.row.shelveStatus == 0" type="text" @click="handleUpdate(scope.row)">编辑</e-button>
                </span>
                <!-- scope.row.draftType == 1 && -->
                <span style="margin-left: 10px;">
                  <el-button :class="{'text':scope.row.shelveStatus ==0}" v-hasPermi="['globalField:productScheme:selectModel']" v-if="scope.row.shelveStatus == 0 && scope.row.vehicleRangeType == 1" type="text" @click="selectModel(scope.row)">选择车型</el-button>
                </span>
              </div>
            </template>
          </el-table-column>
        </template>
        <!-- 普通列插槽 -->
        <template slot="tableCol">
          <el-table-column label="车型范围" align="center" prop="vehicleRangeType">
            <template slot-scope="scope">
              <span :class="{'blue':scope.row.shelveStatus == 1}">{{scope.row.vehicleRangeType == 0?'全部车型':'部分车型'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="业务来源" align="center" prop="businessSource">
            <template slot-scope="scope">
              <span :class="{'blue':scope.row.shelveStatus == 1}">{{scope.row.businessSource == 1?'自营':'渠道'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="方案类型" align="center" prop="schemeType">
            <template slot-scope="scope">
              <span :class="{'blue':scope.row.shelveStatus == 1}">{{scope.row.schemeType == 1?'常规':'特殊'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="产品方案编号" align="center" width="170px" show-overflow-tooltip>
            <template slot-scope="scope">
              <span :class="{'blue':scope.row.shelveStatus == 1}">{{scope.row.schemeNo}}</span>
            </template>
          </el-table-column>
          <el-table-column label="产品方案名称" align="center" min-width="200px" show-overflow-tooltip>
            <template slot-scope="scope">
              <span :class="{'blue':scope.row.shelveStatus == 1}">{{scope.row.schemeName}}</span>
            </template>
          </el-table-column>
          <el-table-column label="生效时间" align="center" width="170px">
            <template slot-scope="scope">
              <span :class="{'blue':scope.row.shelveStatus == 1}">{{ scope.row.effectiveStartTime }} 至 {{ scope.row.effectiveEndTime }}</span>
            </template>
          </el-table-column>
          <el-table-column label="编辑人员" align="center" width="150">
            <template slot-scope="scope">
              <span :class="{'blue':scope.row.shelveStatus == 1}">{{scope.row.editUserName}}</span>
            </template>
          </el-table-column>
          <el-table-column label="编辑时间" align="center" width="150px">
            <template slot-scope="scope">
              <span :class="{'blue':scope.row.shelveStatus == 1}">{{scope.row.editTime}}</span>
            </template>
          </el-table-column>
          <el-table-column label="编辑人员所属组织名称" align="center" width="170px">
            <template slot-scope="scope">
              <span :class="{'blue':scope.row.shelveStatus == 1}">{{scope.row.editUserDeptName}}</span>
            </template>
          </el-table-column>
          <el-table-column label="编辑人员联系方式" align="center" width="130px">
            <template slot-scope="scope">
              <span :class="{'blue':scope.row.shelveStatus == 1}">{{scope.row.editUserPhone}}</span>
            </template>
          </el-table-column>
          <el-table-column label="上架人员" align="center" width="150">
            <template slot-scope="scope">
              <span :class="{'blue':scope.row.shelveStatus == 1}">{{scope.row.shelveUserName}}</span>
            </template>
          </el-table-column>
          <el-table-column label="上架时间" align="center" width="170px">
            <template slot-scope="scope">
              <span :class="{'blue':scope.row.shelveStatus == 1}">{{scope.row.shelveTime}}</span>
            </template>
          </el-table-column>
          <el-table-column label="上架人员所属组织名称" align="center" width="170px">
            <template slot-scope="scope">
              <span :class="{'blue':scope.row.shelveStatus == 1}">{{scope.row.shelveUserDeptName}}</span>
            </template>
          </el-table-column>
          <el-table-column label="上架人员联系方式" align="center" width="130px">
            <template slot-scope="scope">
              <span :class="{'blue':scope.row.shelveStatus == 1}">{{scope.row.shelveUserPhone}}</span>
            </template>
          </el-table-column>
          <el-table-column label="版本号" align="center">
            <template slot-scope="scope">
              <span :class="{'blue':scope.row.shelveStatus == 1}">{{scope.row.version}}</span>
            </template>
          </el-table-column>
        </template>
      </table-page>
    </div>
  </div>
</template>

    <script>
import SearchContent from "@/components/SearchContent/index.vue";
import { getProductList, updateShelveStatus, getConditions } from "@/api/globalField";

export default {
  name: 'ProductScheme',
  components: {
    SearchContent,
  },
  dicts: [
    "mon_ths",
    "business_source",
    "product_solution_name",
    "product_scheme_type",
    "product_solution_status",
    "vehicle_range",
  ],
  data() {
    return {
      schemeNameList: [],
      schemeNoList: [],
      editUserNameList: [],
      versionList: [],
      // 遮罩层
      loading: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      pageSizes: [10, 20, 30, 50, 100],
      total: 0,
      dataList: [],
    };
  },
  created() {
    this.getList();
    this.getConditions()
  },
  methods: {
    getConditions() {
      getConditions().then((res) => {
        this.schemeNameList = res.data.schemeNameList;
        this.schemeNoList = res.data.schemeNoList;
        this.editUserNameList = res.data.editUserNameList;
        this.versionList = res.data.versionList;
      });
    },
    // 详情
    goToDetail(row) {
      console.log("详情", row);
      this._toPage({
        name: "DetailView",
        query: {
          type: "detail",
          id: row.id,
          beForm: "DetailView",
        },
      });
    },
    // 上架
    listing(row) {
      this.$confirm('确认上架？, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        updateShelveStatus({
          id: row.id,
          shelveStatus: 1,
        }).then((res) => {
          this.$message({
            type: "success",
            message: "上架成功",
          });
          this.getList();
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消上架'
        });
      });

    },
    // 下架
    delist(row) {
      this.$confirm('确认下架？, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        updateShelveStatus({
          id: row.id,
          shelveStatus: 0,
        }).then((res) => {
          this.$message({
            type: "success",
            message: "下架成功",
          });
          this.getList();
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消下架'
        });
      });
    },
    // 选择车型
    selectModel(row) {
      this._toPage({
        name: "AddVehicleType",
        query: {
          type: "add",
          beForm: "ProductScheme",
          id: row.id,
        },
      });
    },
    /** 查询测试单表列表 */
    getList() {
      this.loading = true;
      getProductList(this.queryParams).then((res) => {
        if (res.code == "200") {
          const { rows, total } = res;
          this.dataList = rows;
          this.total = total;
          this.loading = false;
        }
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      (this.queryParams = {
        pageNum: 1,
        pageSize: 10,
      }),
        this.handleQuery();
    },
    /** 新增操作 */
    handleAdd() {
      this._toPage({
        path: "/product/AddView",
        name: "AddView",
        query: {
          type: 'add'
        }
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this._toPage({
        path: "/product/EditView",
        name: "EditView",
        query: {
          type: "edit",
          id: row.id,
          beForm: "EditView",
        },
      });
    },
  },
};
</script>


<style lang="scss" scoped>
.pagination-container {
  padding: 0 20px 50px !important;
}

.form-dialog {
  ::v-deep .el-dialog__header {
    padding: 10px 20px;
    border-bottom: 1px solid #dcdfe6;

    .el-dialog__headerbtn {
      top: 15px;
    }
  }

  .box-card {
    margin-bottom: 20px;

    .card-title {
      font-size: 16px;
      position: relative;
      margin-left: 8px;
      padding: 0;
    }

    .card-title::after {
      content: "";
      width: 4px;
      height: 18px;
      background-color: aqua;
      display: block;
      position: absolute;
      left: -12px;
      top: 2px;
    }
  }
}
.text {
  color: #606266 !important;
}
.blue {
  color: #1890ff !important;
}
</style>
